<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客户信息</title>
<%@ include file="../../common_header.jsp"%>
<script type="text/javascript" src="${ctx}/js/other.js"></script>
<style type="text/css" media="screen">
.btn{
   	border-right: #63B8FF 1px solid;
  	padding-right: 2px;
   	border-top: #63B8FF 1px solid;
   	padding-left: 2px;
   	font-size: 12px;
   	FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,  StartColorStr=#ffffff,  EndColorStr=#C3DAF5);
   	border-left: #63B8FF 1px solid;
   	cursor: hand;
   	color: black;
   	padding-top: 2px;
   	border-bottom: #63B8FF 1px solid;
}
</style>
</head>
<body class="easyui-layout">		
	<div data-options="region:'north',border:false"
		style="height: 0px; background: #F0FFF0; padding: 5px">	
		<form id="formModule" method="post">
		 所属单位：<select id="depId" name="sysDepartment.depId" style="width:150px" class="easyui-combotree" style="width:232px;height:23px" data-options="required:true,editable:false"></select>
    		姓名：<input id="NAME"  maxlength="10" onchange="searchit();" class="easyui-validatebox textbox" type="text"  name="custName" style="width:150px" ></input>                      
                                    手机号：<input id="PHONE" onchange="searchit();"  maxlength="14" onkeyup="value=value.replace(/[^1234567890-]+/g,'')" class="easyui-validatebox textbox" type="text" name="phone" style="width:150px"></input>                                                   
                                性别：<select id="sex" name="sex" onchange="searchit();">
                            <option value=""  >--全部--</option>
                            <option value="1"  >男</option>
                            <option value="2"  >女</option>
                </select>
                              状态：<select id="status" name="status" onchange="searchit();">
                            <option value=""  >--全部--</option>
                            <option value="9"  >正常</option>
                            <option value="1"  >注销</option>
                            <option value="0"  >移除</option>
                </select>           
    	</form>
		</div>
	<div data-options="region:'center',title:''">
		<table id="dg" class="easyui-datagrid" title="客户信息" fit="true"
			style="width: 700px; height: 250px"
			data-options="rownumbers:true,singleSelect:true,url:'/manage/sysCustomer/dataGrid',method:'get',toolbar:'#toolbar',fit:true,
				showFooter:false,singleSelect:false,pagination:true,idField:'custId'">
			<thead>
				<tr>
					<th data-options="field:'ck',checkbox:true">全选</th>
					<th data-options="field:'sysDepartment',width:130,align:'center',formatter:showDept">所属单位</th>
					<th data-options="field:'custName',width:100,align:'center'">姓名</th>
					<th data-options="field:'phone',width:120,align:'center'">联系电话</th>
					<th data-options="field:'sex',width:50,align:'center',formatter:showCustSex">性别</th>
					<th data-options="field:'status',width:70,align:'center',formatter:showStatus">状态</th>
					<th data-options="field:'_operate',width:180,align:'center',formatter:formatOper">操作</th>
				</tr>
			</thead>
		</table>
		<div id="toolbar" style="height: auto;background: #F0FFF0">
			${buttons }
			<script type="text/javascript">
				function append() {
					var params = {
		    	                winId:'win_adds_sysCustomerss',
		    	                title:'添加客户信息',
		    	                width:350,
		    	                height:300,
		    	                showUrl:'${ctx}/manage/sysCustomer/add',
		    	                refresh_fun:function(){
		    	                	$('#dg').datagrid('uncheckAll');
		    	                    $('#dg').datagrid('reload');
		    	                }
		    	                
		    	        };
		    	        open_fun(params);
				}
				function edit() {
					 	var id=0;
		                var name=null;
		                var row = $('#dg').datagrid('getSelected');
		            	//var row = $('#dg').datagrid('getSelections');
		            	var len = $('#dg').datagrid('getSelections').length; 
		            	
		               	if(len>1){
		               		$.messager.alert("系统提示","只能选择一个进行更改!");
		               	}
		               	else if(len==1 && row)
		                {
		                    id = row.custId;
		                    name = row.custName;
		                        //winId,title,width,height,showUrl,okUrl,refresh_fun
		                        var params = {
		                                winId:'win_edit_syscustomer',
		                                title:'修改 '+name+' 的资料',
		                                width:350,
		                                height:300,
		                                showUrl:'${ctx}/manage/sysCustomer/edit?id='+id,
		                                refresh_fun:function(){
		                                	$('#dg').datagrid('uncheckAll');
		                                    $('#dg').datagrid('reload');
		                                }
		                        };
		                        open_fun(params);   
		                }           
		                else
		                {
		                    $.messager.alert("系统提示","请选择要修改的信息!");
		                }
				}
				function removeit() {
					var ids = [];
		        	var rows = $('#dg').datagrid('getSelections');
		        	var len = $('#dg').datagrid('getSelections').length; 
		        	for(var i=0; i<rows.length; i++){
		        		ids.push(rows[i].custId);
		        	}
		            if(!len)
		            {
		                $.messager.alert("系统提示","请选择要移除的数据！");
		            }
		            else
		            {
		                $.messager.confirm("移除确认","是否要移除你选择的数据到回收站？",function(conf){
		                    if(conf)
		                    {
		                        var url = "${ctx}/manage/sysCustomer/remove?ids="+ids;
		                        $.getJSON(url, function(json){
		                            if(json.success==0)
		                            {
		                            	
		                            	$('#dg').datagrid('uncheckAll');
		                                $('#dg').datagrid('reload');
		                            }
		                            else
		                            {
		                                showErrMsg(json);
		                            }
		                        });
		                    }                                       
		                });
		            }
				}
				function deleteit() {
					var ids = [];
		        	var len = $('#dg').datagrid('getSelections').length; 
		        	var rows = $('#dg').datagrid('getSelections');
		        	for(var i=0; i<rows.length; i++){
		        		ids.push(rows[i].custId);
		        	}
		            if(!len)
		            {
		                $.messager.alert("系统提示","请选择要删除的数据！");
		            }
		            else
		            {	
		                $.messager.confirm("系统提示","是否要删除你选择的数据？",function(conf){
		                    if(conf)
		                    {	
		                        var url = "${ctx}/manage/sysCustomer/delete?ids="+ids;
		                        $.getJSON(url, function(json){
		                            if(json.success==0)
		                            {
		                            	$('#dg').datagrid('uncheckAll');
		                                $('#dg').datagrid('reload');
		                            }
		                            else
		                            {
		                            	$.messager.alert("删除失败",json.msg);
		                            }
		                        });
		                    }                                       
		                });
		            }
				}
				function searchit() {
					$("#dg").datagrid("load", sy.serializeObject($('#formModule').form()));
				}
				//右侧菜单
				function formatOper(val, row, index) {
					return '<a href="#" onclick="editone();"><input class="btn" type="button" value="修改" ></a>  <a href="#" onclick="deleteone();"><input class="btn" type="button" value="删除" ></a>  <a href="#" onclick="removeone();"><input class="btn" type="button" value="移除" ></a>';
				}
				//格式化日期
				function formatDate (strTime) {
					 var date = new Date(strTime);
					if(strTime == "" || strTime == null ){
						return "";
					}else{
						 return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
					}
				}
				 //以下三个函数为单个操作
		        function editone(){
		        	var row = $('#dg').datagrid('getSelected');
		        	var id = row.custId;
		        	var name = row.custName;
		            var params = {
		                    winId:'win_edit_sysCustomer',
		                    title:'修改 '+name+' 的信息',
		                    width:350,
		                    height:300,
		                    showUrl:'${ctx}/manage/sysCustomer/edit?id='+id,
		                    refresh_fun:function(){
		                    	$('#dg').datagrid('uncheckAll');
		                        $('#dg').datagrid('reload');
		                    }
		            };
		            open_fun(params);   
		        }
		        function removeone(){
		        	var row = $('#dg').datagrid('getSelected');
		        	var id = row.custId;
		        	var name = row.custName;
		        	 $.messager.confirm("移除确认",'移除&nbsp; <span style="color:red;font-weight:bold">'+id+'-'+name+'</span> &nbsp;？',function(conf){
		                 if(conf)
		                 {
		                     var url = "${ctx}/manage/sysCustomer/remove?ids="+id;
		                     $.getJSON(url, function(json){
		                         if(json.success==0)
		                         {
		                         	
		                         	$('#dg').datagrid('uncheckAll');
		                             $('#dg').datagrid('reload');
		                         }
		                         else
		                         {
		                             showErrMsg(json);
		                         }
		                     });
		                 }                                       
		             });
		        }
		        function deleteone(){
		        	var row = $('#dg').datagrid('getSelected');
		        	var id = row.custId;
		        	var name = row.custName;
		        	 $.messager.confirm("删除确认",'删除&nbsp; <span style="color:red;font-weight:bold">'+id+'-'+name+'</span> &nbsp;？',function(conf){
		                 if(conf)
		                 {	
		                     var url = "${ctx}/manage/sysCustomer/delete?ids="+id;
		                     $.getJSON(url, function(json){
		                         if(json.success==0)
		                         {
		                         	$('#dg').datagrid('uncheckAll');
		                             $('#dg').datagrid('reload');
		                         }
		                         else
		                         {
		                        	 showErrMsg(json);
		                         }
		                     });
		                 }                                       
		             });
		        }
		        //显示用户详细
		    	function show_fun()
		    	{
		    			var row = $('#dg').datagrid('getSelected');
		        		var id = row.custId;
		        		var name = row.custName;
		    	       var params = {
		    	                winId:'win_showuser_sysCustomer',
		    	                title:name+'的详细资料',
		    	                width:700,
		    	                height:425,
		    	                showUrl:'${ctx}/manage/sysCustomer/queryCustDetail?id='+id,
		    	                refresh_fun:function(json){
		  
		     	                	$('#dg').datagrid('uncheckAll');
		      	                    $('#dg').datagrid('reload');
		    	                }
		    	        };
		    	       ShowUserFun(params);
		    	}
		    	 $(document).ready(function(){
		    			//获取当前用户可查看到的部门
		    			showDataInCombotree('${ctx }/manage/sysDepartment/getAllDepaetment?flag=2',$("#depId"),'${model.sysDepartment.depId}');
		    			$("#depId").combobox({
		            		onChange: function (n,o) {
		            			searchit();
		            		}
		            	})
		    		  });
			</script>
		</div>
	</div>
</body>
</html>